package com.fc.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fc.entity.User;
import com.fc.vo.UserVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    @Select("SELECT role_name FROM role r  INNER JOIN user_role ur  ON ur.role_id = r.id WHERE ur.user_id = #{userId}")
    List<String> selectRolesByUserId(Long userId);

    @Select("select role_id from user_role where user_id=#{id}")
    Long selectRoleIdByUserId(Long userId);

    @Insert("insert into user_role (user_id, role_id) values (#{userId},#{roleId})")
    void insertUserRole(Long userId, Long roleId);

    @Delete("delete from user_role where user_id=#{userId}")
    void deleteUserRole(Long userId);

    List<UserVO> list(String username, String name);
}
